<?php
/**
 * 用户标签
 */

namespace App\backend\controllers\member;

use App\backend\models\MemberGroupModel;
use App\backend\controllers\AdminBaseController;
use App\backend\services\MemberGroupServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class MemberGroupController extends AdminBaseController
{

    protected $memberGroupServices;

    public function __construct(MemberGroupServices $memberGroupServices)
    {
        $this->memberGroupServices = $memberGroupServices;
    }

    /**
     * 列表
     */
    public function list(Request $request)
    {
        $request = $request->all();
        $result = $this->memberGroupServices->list($request);
        return successJson('成功！', $result);

    }

    /**
     * 详情
     */
    public function details(Request $request)
    {
        $request = $request->all();
        $result = $this->memberGroupServices->details($request);
        return successJson('成功！', $result);

    }

    /**
     * 添加
     */
    public function addGroup(Request $request)
    {
        $request = $request->all();
        $validator = Validator::make(
            $request,
            MemberGroupModel::rules(),
            MemberGroupModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return JsonResp::error($msg[0]);
        }
        $result = $this->memberGroupServices->addGroup($request);
        return successJson('成功！', $result);
    }

    /**
     * 编辑
     */
    public function editGroup(Request $request)
    {
        $request = $request->all();
        $validator = Validator::make(
            $request,
            MemberGroupModel::rules(),
            MemberGroupModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return JsonResp::error($msg[0]);
        }
        $result = $this->memberGroupServices->editGroup($request);
        return successJson('成功！', $result);
    }

    /**
     * 删除
     */
    public function deleteGroup(Request $request)
    {
        $request = $request->all();
        $result = $this->memberGroupServices->deleteGroup($request);
        return successJson('成功！', $result);
    }

}
